package com.tyk.bookstore.front.member.controller;


import com.tyk.bookstore.front.common.core.model.result.R;
import com.tyk.bookstore.front.common.other.code.behavior.model.enume.SceneType;
import com.tyk.bookstore.front.member.model.query.MemberRegisterQuery;
import com.tyk.bookstore.front.member.model.query.MsgCodeCheckQuery;
import com.tyk.bookstore.front.member.model.query.MsgCodeSendWithBehaviorCheckQuery;
import com.tyk.bookstore.front.member.model.vo.MemberRegisterVo;
import com.tyk.bookstore.front.member.service.MemberService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "会员管理/注册中心", description = "注册中心")
@RequestMapping({"api/member/register"})
@RestController
@Validated
@RequiredArgsConstructor
public class RegisterController {

    private final MemberService memberService;

    @PostMapping({"code/msg/phone/check-send"})
    @Operation(summary = "发送手机验证码(注册,含行为验证码校验)", description = "发送手机验证码(注册,含行为验证码校验)")
    public R<String> sendMsgCode4RegisterWithBehaviorCheck(
            @Validated @RequestBody MsgCodeSendWithBehaviorCheckQuery query
    ) {
        return R.ok(memberService.sendMsgCodeWithBehaviorCheck(query, SceneType.REGISTER));
    }

    @PostMapping({"code/msg/phone/check"})
    @Operation(summary = "校验手机验证码(注册)", description = "校验手机验证码(注册)")
    public R<String> checkMsgCode4Register(
            @Validated @RequestBody MsgCodeCheckQuery query
    ) {
        return R.ok(memberService.checkMsgCode(query, SceneType.REGISTER));
    }


    @PostMapping
    @Operation(summary = "会员注册", description = "会员注册")
    public R<MemberRegisterVo> register(
            @Validated @RequestBody MemberRegisterQuery query
    ) {
        return R.ok(memberService.register(query));
    }


}
